package com.vegetable.common.utils;

import cn.hutool.core.util.StrUtil;

import java.util.Arrays;
import java.util.List;

/**
 * 常量
 *
 * @author Mark sunlightcs@gmail.com
 */
public class Constant {
	/** 超级管理员ID */
	public static final int SUPER_ADMIN = 1;
    /**
     * 当前页码
     */
    public static final String PAGE = "page";
    /**
     * 每页显示记录数
     */
    public static final String LIMIT = "limit";
    /**
     * 排序字段
     */
    public static final String ORDER_FIELD = "sidx";
    /**
     * 排序方式
     */
    public static final String ORDER = "order";
    /**
     *  升序
     */
    public static final String ASC = "asc";

    /**
     *  仓库默认id
     */
    public static final Long WAREHOUSE_ID = 1L;

    /**
     *  仓库默认名称
     */
    public static final String WAREHOUSE_NAME = "1号仓库";

    /**
     *  仓库默认名称
     */
    public static final String LOGISTICS_PARK = "物流园";
	/**
	 * 菜单类型
	 * 
	 * @author chenshun
	 * @email sunlightcs@gmail.com
	 * @date 2016年11月15日 下午1:24:29
	 */
    public enum MenuType {
        /**
         * 目录
         */
    	CATALOG(0),
        /**
         * 菜单
         */
        MENU(1),
        /**
         * 按钮
         */
        BUTTON(2);

        private final int value;

        MenuType(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }
    }
    
    /**
     * 定时任务状态
     * 
     * @author chenshun
     * @email sunlightcs@gmail.com
     * @date 2016年12月3日 上午12:07:22
     */
    public enum ScheduleStatus {
        /**
         * 正常
         */
    	NORMAL(0),
        /**
         * 暂停
         */
    	PAUSE(1);

        private final int value;

        ScheduleStatus(int value) {
            this.value = value;
        }
        
        public int getValue() {
            return value;
        }
    }

    /**
     * 云服务商
     */
    public enum CloudService {
        /**
         * 七牛云
         */
        QINIU(1),
        /**
         * 阿里云
         */
        ALIYUN(2),
        /**
         * 腾讯云
         */
        QCLOUD(3);

        private final int value;

        CloudService(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }
    }

    /**
     * 入库类型：0 代办交货 1 物流园 2 散货采购
     */
    public enum InStorageType {
        /**
         * 代办交货
         */
        AGENT(0),
        /**
         * 物流园
         */
        LOGISTICS(1),
        /**
         * 散货
         */
        BULK(2);

        private final int value;

        InStorageType(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }
    }

    /**
     * 库存流水类型
     * 0 代办交货入库 1 物流园采购入库 2 散货采购入库 4 销售退货入库 5 盘盈入库 6 其他入库 7 销售出库 8 盘损出库 9 采购退货出库 10 调拨出库 11 调拨入库 12 代销出库 13 其他出库
     */
    public enum StockFlowType {
        AGENT_IN(0, "代办交货入库"),
        LOGISTICS_IN(1, "物流园入库"),
        BULK_IN(2, "散货"),
        SALE_RETURN_IN(4, "销售退货入库"),
        INVENTORY_IN(5, "盘盈入库"),
        OTHER_IN(6, "其他入库"),
        SALE_OUT(7, "销售出库"),
        INVENTORY_OUT(8, "盘损出库"),
        PURCHASE_RETURN_OUT(9, "采购退货出库"),
        ALLOCATION_IN(10, "调拨入库"),
        ALLOCATION_OUT(11, "调拨出库"),
        AGENT_SALE_OUT(12, "代销出库"),
        OTHER_OUT(13, "其他出库"),
        WORK_IN(14, "加工入库"),
        WORK_OUT(15, "加工出库"),
        WORK_RETURN_IN(16, "加工退货入库"),
        WORK_RETURN_OUT(16, "加工退货出库");


        private final int value;
        private final String name;

        StockFlowType(int value, String name) {
            this.value = value;
            this.name = name;
        }

        public int getValue() {
            return value;
        }

        public String getName() {
            return name;
        }

        public static StockFlowType getFromPDType(int PDType) {
            // 类型0采购散货，1物流园，2采购包装
            switch (PDType) {
                case 0:
                    return BULK_IN;
                case 1:
                    return LOGISTICS_IN;
                default:
                    return BULK_IN;
            }
        }

        public static StockFlowType resolveFromPDType(int PDType) {
            StockFlowType result = null;
            // 类型0采购散货，1物流园，2采购包装
            StockFlowType[] types = StockFlowType.values();
            for(StockFlowType flowType : types){
                if(PDType == flowType.getValue()){
                    result = flowType;
                }
            }
            return result;
        }

        /**
         * 判断是不是入库类型
         *
         * @param type
         * @return
         */
        public static Boolean isInType(Integer type) {
            List<Integer> inTypes = Arrays.asList(0, 1, 2, 4, 5, 6, 10, 14);
            return inTypes.contains(type);
        }

        public static Boolean isInAType(Integer type) {
            List<Integer> inTypes = Arrays.asList(4, 5);
            return inTypes.contains(type);
        }

        public static List inTypeList() {
            List<Integer> inTypes = Arrays.asList(0, 1, 2, 4, 5, 6, 10, 14);
            return inTypes;
        }

        public static List outTypeList() {
            List<Integer> inTypes = Arrays.asList(3, 7, 8, 9, 11, 12, 13, 15);
            return inTypes;
        }
    }

    /**
     * 财务收支类型
     */
    public enum MoneyTYPE{
        AGENT_OUT(0, "代办付款"),
        TEAM_OUT(1, "班组付款"),
        OTHER_OUT(2, "其他付款"),
        PURCHASE_OUT(3, "采购付款"),
        TRANSFER_OUT(4, "转账付款"),
        SALES_IN(5, "销售收款"),
        OTHER_IN(6, "其他收款"),
        TRANSFER_IN(7, "转账收款");

        private final int value;
        private final String name;
        MoneyTYPE(int value, String name) {
            this.value = value;
            this.name = name;
        }

        public int getValue() {
            return value;
        }

        public String getName() {
            return name;
        }
        public static List outTypeList() {
            List<Integer> outTypes = Arrays.asList(0, 1, 2, 3, 4);
            return outTypes;
        }
        public static Boolean isOutType(Integer type) {
            return outTypeList().contains(type);
        }
    }

    /**
     * 结算台账地区枚举
     */
    public enum LedgerRegion {
        /**
         * 寿光地区
         */
        SHOUGUANG(0, "寿光"),
        
        /**
         * 河北地区
         */
        HEBEI(1, "河北"),
        
        /**
         * 聊城地区
         */
        LIAOCHENG(2, "聊城"),
        
        /**
         * 云南地区
         */
        YUNNAN(3, "云南");

        private final int code;
        private final String name;

        LedgerRegion(int code, String name) {
            this.code = code;
            this.name = name;
        }

        public int getCode() {
            return code;
        }

        public String getName() {
            return name;
        }

        /**
         * 根据code获取地区名称
         * @param code 地区code
         * @return 地区名称
         */
        public static String getNameByCode(Integer code) {
            String name = null;
            for (LedgerRegion region : LedgerRegion.values()) {
                if (region.getCode() == code) {
                    name = region.getName();
                }
            }
            return name;
        }
        public static Integer getCodeByName(String name) {
            Integer code = null;
            for (LedgerRegion region : LedgerRegion.values()) {
                if (StrUtil.equals(name, region.getName()) || name.contains(region.getName())) {
                    code = region.getCode();
                }
            }
            return code;
        }
    }

}
